#include "Message.h"
#include <sstream>
#include <iostream>

using namespace std;

Message::Message(void* message)
{
	m_message=(char*)message;
	char* arg;
	list = tokenizer.parse(m_message," ","\n");
	len = tokenizer.length(list);
	m_brokenMessage = new char*[len];
	for(i=0; i<len; i++){
		m_brokenMessage[i] = list->str;
		list = list->next;
	}

}

Message::Message(int type, int from, int to, int dest, char* message)
{
	m_message=(char*)message;	
	char* arg;
	list = tokenizer.parse(m_message," ","\n");
	len = tokenizer.length(list);
	m_brokenMessage = new char*[len];
	for(i=0; i<len; i++){
		m_brokenMessage[i] = list->str;
		list = list->next;
	}
	 
	_from=from;
	_to=to;
	_dest=dest;
	_type=type;
	
}

Message::Message(int type, int from, int to, RT* message)
{
	_routing=message;
	_from=from;
	_to=to;
	_type=type;
}

Message::Message(Message* msg)
{
	_routing=msg->_routing;
	_from=msg->_from;
	_to=msg->_to;
	_dest=msg->_dest;
	_type=msg->_type;
	m_message=msg->m_message;
	m_brokenMessage=msg->m_brokenMessage;
}


Message::~Message(){}

char* Message::text()
{
	return m_message;
}

int Message::type()
{
	return _type;
}

int Message::from()
{
	return _from;
}

int Message::to()
{
	return _to;
}

int Message::dest() 
{
	return _dest;
}

RT* Message::getRT()
{
	return _routing;
}

void Message::set_to(int k)
{
	_to=k;
}

void Message::set_dest(int k)
{
	_dest=k;
}

void Message::set_type(int k)
{
	_type=k;
}

void Message::set_from(int k)
{
	_from=k;
}

void Message::setRT(RT* toset)
{
	_routing=toset;
}

char* Message::getMessageAtIndex(int i)
{
	return m_brokenMessage[i];
}

char** Message::getBrokenMessage()
{
	return m_brokenMessage;
}



